﻿namespace Sharemarker.DataAccess
{
    using System.Data.Linq;

    using Autofac;

    using Sharemarker.Common.DataAccess;
    using Sharemarker.DataAccess.Implement;
    using Sharemarker.DataAccess.Mysql;

    using log4net;

    public class DependencyDataAcessRegister
    {
        #region Static Fields

        /// <summary>
        /// 
        /// </summary>
        private static readonly ILog Logger = LogManager.GetLogger(typeof(DependencyDataAcessRegister));

        #endregion

        #region Public Methods and Operators

        /// <summary>
        /// Registers the specified container builder.
        /// </summary>
        /// <param name="containerBuilder">The container builder.</param>
        public static void Register(ContainerBuilder containerBuilder)
        {
            containerBuilder.Register<IHeaderRepository>(
                context => new HeaderRepository(context.Resolve<IUnitOfWork<DataContext>>()));
            containerBuilder.Register<IQuoteRepository>(
                context => new QuoteRepository(context.Resolve<IUnitOfWork<DataContext>>()));
        }

        /// <summary>
        /// Registers the specified container builder.
        /// </summary>
        /// <param name="containerBuilder">The container builder.</param>
        /// <param name="connectionString">The connection string.</param>
        public static void Register(ContainerBuilder containerBuilder, string connectionString)
        {
            containerBuilder.Register<ISharemarkerAccountRepository>(
                context => new SharemarkerAccountRepository(connectionString)).PropertiesAutowired().SingleInstance();
        }

        #endregion
    }
}